<template>
  <div class="navitem" @click="navbarItemClick">
    <div v-if="!isActive">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="item-icon-active"></slot>
    </div>
    <div :style="activeStyle"><slot name="item-text"></slot></div>
  </div>
</template>

<script>
export default {
  name: "navbarItem",
  props: {
    path: String,
    activeColor: {
      type: String,
      default: "black",
    },
  },
  data() {
    return {
      userId: "123",
      name: "lihanmin",
      // isActive: true,
    };
  },
  methods: {
    navbarItemClick() {
      // console.log("this.path :>> ", this.path);
      this.$router.replace(this.path);
    },
  },
  computed: {
    isActive() {
      // console.log("this.$route.path :>> ", this.$router.path);
      return this.$route.path.indexOf(this.path) !== -1;
    },
    activeStyle() {
      return this.isActive ? { color: this.activeColor } : {};
    },
  },
};
</script>

<style>
@import "@/src/assets/css/base.css";

.navitem {
  flex: 1;
  height: 49px;
  text-align: center;
  font-size: 14px;
}

.navitem img {
  height: 25px;
  width: 25px;
  margin: top 3px;
  vertical-align: middle;
}
</style>